<?php
	$writePost = "<?php
$%SQLconnect = mysql_connect(\"$db_host\",\"$db_username\",\"$db_password\");
$%bodyString = \"\";
if ($%_SERVER['REQUEST_METHOD']==\"POST\") {
	$%id = $%_POST['id'];\n
	if ($%id) {
$postDataVarsString
		$%SQLedit = \"UPDATE $tableName SET \";	
		$%SQLedit .= \" $editPostDataSQLString \"; 
		$%SQLedit .= \" WHERE id = '$%id' \";
		$%SQLeditResult = mysql_db_query(\"$db_name\",\"$%SQLedit\",$%SQLconnect);
		if (!$%SQLeditResult) { echo(\"EDIT ERROR: \" . mysql_error() . \"$%SQLedit\");	}
	}
	else {
$postDataVarsString
		$%SQLnew = \"INSERT INTO $tableName ($newNamesPostDataSQLString) VALUES ($newValuesPostDataSQLString)\";
		$%SQLnewResult = mysql_db_query(\"$db_name\",\"$%SQLnew\",$%SQLconnect);
		if (!$%SQLnewResult) { echo(\"NEW ERROR: \" . mysql_error() . \"$%SQLnew\");	}
	}
}
";
	$writeHead = "$%SQLlist = \"SELECT * FROM $tableName WHERE $"."parentTable_SQL_where\";
	
if (!$%SQLconnect) { echo(\"SQL Connection Error: \" . mysql_error() . \"\\n\");	}\n
else {
	$%SQLexecute = mysql_db_query(\"$db_name\",$%SQLlist,$%SQLconnect);
	if (!$%SQLexecute) { echo(\"SQL Execution Error: \" . mysql_error() . \"\\n$%SQL\\n\");	}
	else {
		while($%rowArray = mysql_fetch_array($%SQLexecute,MYSQL_ASSOC)) {";

	$writeBody = "\n						
		$%bodyString .= \"\%n<div class='listPageButtons'><a class='editBtn positiveBtns' href='$tableName" . "_write.php?id=$%id&groupItem=\".$%parentTable.\"_write.php?id=\".$$"."parentTable_id.\"'>EDIT</a><div class='deleteBtn'><a class='negativeBtns' href='#'>DELETE</a>\";
		$%bodyString .= \"\%n<div class='deleteConfirmation' id='deleteConfirmation$%id'>Do you really want to delete? <a class='deleteYes'>YES</a> // <a class='deleteNo'>NO</a></div>\";
		$%bodyString .= \"</div></div></div>\";
		}
	}
}
mysql_close($%SQLconnect);
?>
	<script type='text/javascript'>
	var jsTableName = '$tableName';

	$(function() {
		jQuery.fileDelete = function(id,field) {
		$.ajax({
			url: \"ajax.php\",
			data: \"tablename=\"+jsTableName+\"&id=\"+id+\"&field=\"+field+\"&AJAXtask=deleteFile\",
			cache: false,
			complete: function(){
				//alert(\"tablename=\"+jsTableName+\"&id=\"+id+\"&field=\"+field+\"&AJAXtask=deleteFile\");
			}
		});

	};	

	jQuery.deleteAllFiles = function(id,field) {
		$fieldsForDeletionString		
	};		
});
	</script>
	<script src=\"list_actions.js\" type='text/javascript'></script>
	
	<?php echo $%bodyString;";
	$writeFooter = " ?>
	\n
	<a class='newBtn positiveBtns' href='" . $tableName . "_write.php?foreignKey=<?php echo $$"."parentTable_id . \"&groupItem=\".$%parentTable.\"_write.php?id=\".$$"."parentTable_id; ?>'>NEW RECORD</a>
";
	$pageSource = str_replace("%", "", $writePost) . str_replace("%", "", $writeHead) . str_replace("%", "", $fieldVarsString) .  $backListElements . str_replace("%", "", $writeBody) . str_replace("%", "", $writeFooter);
	//echo "<br> <br> backlistelements:" . $backListElements;
	//echo "<br> <br> createList pagesource = " . $pageSource;
	//echo "<h2>tableName = $tableName</h2> ";
	//echo "<br> <br> backlistelements:" . $backListElements;
	//echo "<br> <br> createList pagesource = " . $pageSource;
	//echo "<h2>tableName = $tableName</h2> ";

?>